<?php

#	Fastfoo - CMS developer under CakePHP / http://fast-foo.com
#	Copyright (C) 2010  Antonio Irlandés García

#	This program is free software: you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation, either version 3 of the License, or
#	(at your option) any later version.

#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.

#	You should have received a copy of the GNU General Public License
#	along with this program.  If not, see <http://www.gnu.org/licenses/>.

class BackupController extends AppController{
	
	/*****************
	** Variables Generales
	*****************/
	public $name = 'Backup';//nombre controlador
	public $uses = array('Backup');//modelos empleados
	public $layout = 'admin';//disposición de diseño por defecto

	/*****************
	** Variables Administracion
	*****************/
	public $search_form = false;//mostramos el buscador si o no
	public $sub_menu = array("backup" => "view");//Subsecciones en submenu
	public $action_menu = null;//Acciones del menu accion


////////////////////////////////////////////////////////////////////////////
//////*ESTOS METODOS DEBEN ESTAR LIMITADOS A LOS ADMINISTRADORES*//////////
//////////////////////////////////////////////////////////////////////////


	/**
	 * Muestra la pantalla inicial del backup
	 *
	 * @return void
	 */
	public function admin_index(){

		//Seteo las secciones del menu izquierdo
		$this->set('action_menu', $this->action_menu);

		//Seteo las secciones del submenu
		$this->set('sub_menu', $this->sub_menu);

		//Mostramos el buscador
		$this->set('search_form', $this->search_form);	
	}

	/**
	 * Encargada de llamar al metodo _backup_save para realizar la copia de seguridad
	 *
	 * @return void
	 */
	public function admin_download(){		
		$this->autoRender = false;
		$this->_backup_save();
	}

	/**
	 * Realiza las operaciones pertinentes para generar un paquete comprimido con un backup de la
	 * BD y de la carpeta UPLOAD donde se subieron imágenes de las paǵinas generadas
	 *
	 * @return string file
	 */
	private function _backup_save(){

		$this->autoRender = false;

		####INICIO LOG del sistema
		$data_log = array ( "title" => __("make_backup_download", true),
							"section" => $this->name,
							"url" => null,
							"created" => date("Y-m-d H:i:s")
						);

		$this->Log->addRegister($data_log);
		####FIN LOG

		//Genera Backup
		$this->Backup->makeBackup();

	} 
}
?>
